package EA.testproblems;
import EA.*;

/**
This testproblem is a simple problem for initial tuning of multimodal 
optimization algorithms. <br><br>

<table border="0" cellpadding="2" cellspacing="0">
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem description</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top" width="200"><b>Name:</b></td>
  <td valign="top">Ursem multimodal 4</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Nickname:</b></td>
  <td valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Intended usage:</b></td>
  <td valign="top">Explore the eventually problems with unfortunate mutation.</td>
</tr>

<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem details</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Function:</b></td>
  <td valign="top">3sin(0.5pi*x + 0.5pi)*(2 - sqrt(x<sup>2</sup> + y<sup>2</sup>))/4</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Plots:</b></td>
  <td valign="top"><img src="../../images/testproblems/ursemmultimodal4.gif">&nbsp;&nbsp;
<img src="../../images/testproblems/ursemmultimodal4_contour.gif"></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Ranges:</b></td>
  <td valign="top">x = [-2.0:2.0]&nbsp;&nbsp;y = [-2.0:2.0] </td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Type:</b></td>
  <td valign="top">Maximization</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of maximas:</b></td>
  <td valign="top">5</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of minimas:</b></td>
  <td valign="top">0</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optimum radius:</b></td>
  <td valign="top">0.2
</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optimum descriptions:</b></td>
  <td valign="top">The global maxima is located at (0,0). The 4 local 
  maximas has equal height and are located at the corners of the search space.</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Known optimums:</b></td>
  <td valign="top">GMAX(0,0), LMAX(2,2), LMAX(-2,2), LMAX(2,-2), LMAX(-2,-2)<br><font size=1>Capital letters 
means that the precise optimum is known, lowercase letters is the best known 
so far.</font></td>
</tr>
<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Plotting details</b></td>
</tr>

<tr bgcolor="#e0e0e0">
  <td valign="top"><b>GNUPlot code:</b></td>
  <td valign="top">
  set hidden3d<br>
  set isosamples 40<br>
  set view 70,15<br>
  splot [-2:2] [-2:2] 3*sin(0.5*pi*x + 0.5*pi)*(2 - sqrt(x*x + y*y))/4
</td>

</tr>

</table>

*/
public class UrsemMultimodal4 extends NumericalProblem
{

  public UrsemMultimodal4()
    {
      super();

      double[] optimums;

      name = "Ursem Multimodal 4";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		  return 3*Math.sin(0.5*Math.PI*realpos[0] + 0.5*Math.PI)*(2 - Math.sqrt(realpos[0]*realpos[0] + realpos[1]*realpos[1]))/4;

	      };
	  };

      dimensions = 2;
      ismaximization = true;
      optimumradius = 0.2;

      intervals = new Interval[2];
      intervals[0] = new Interval(-2,2);
      intervals[1] = new Interval(-2,2);

      // Set up known maximas
      knownmaxima = new NumericalOptimum[5];

      optimums = new double[dimensions];
      optimums[0] = 0;
      optimums[1] = 0;
      knownmaxima[0] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), true, false, 0);

      optimums = new double[dimensions];
      optimums[0] = 2;
      optimums[1] = 2;
      knownmaxima[1] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), true, false, 1);

      optimums = new double[dimensions];
      optimums[0] = -2;
      optimums[1] = 2;
      knownmaxima[2] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), true, false, 2);

      optimums = new double[dimensions];
      optimums[0] = 2;
      optimums[1] = -2;
      knownmaxima[3] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), true, false, 3);

      optimums = new double[dimensions];
      optimums[0] = -2;
      optimums[1] = -2;
      knownmaxima[4] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), true, false, 4);

      // Set up known minimas
      knownminima = new NumericalOptimum[0];
    }
}
